using System.Runtime.InteropServices;

namespace DA.AnimGraph {
    public struct ScopeContext {
        float localWeight;
        float globalWeight;
        [MarshalAs(UnmanagedType.U1)] bool isNoCurve;

        [MarshalAs(UnmanagedType.U1)] public bool forceOnEnter; // true:强制调用 OnEnter
        [MarshalAs(UnmanagedType.U1)] public bool disableBlackboardUpdate; // true:不再从黑板更新参数

        public bool canSkipPostEvaluate => isNoCurve;

        public ScopeContext(float weight) {
            localWeight = 1;
            globalWeight = 1;
            isNoCurve = true;
            forceOnEnter = false;
            disableBlackboardUpdate = false;
        }
        public ScopeContext(ScopeContext parent, float weight) {
            localWeight = weight;
            globalWeight = weight * parent.globalWeight;
            isNoCurve = true;
            forceOnEnter = parent.forceOnEnter;
            disableBlackboardUpdate = parent.disableBlackboardUpdate;
        }

        public void Fusion(in ScopeContext other) {
            isNoCurve = isNoCurve && other.isNoCurve;
        }

        public void SetHasCurve() {
            isNoCurve = false;
        }
    }
}
